package com.aoxin.controller.course.systemCourse;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.aoxin.model.course.SlfSyllabus;
import com.aoxin.model.dto.SelectDto;
import com.aoxin.model.dto.SlfSyllabusDto;
import com.aoxin.service.inter.course.systemCourse.SyllabusService;
import com.aoxin.util.AjaxRes;
import com.aoxin.util.Const;

/**
 * 课表 Syllabus
 * 
 * @author Melody
 * @date 2018年3月27日 下午2:56:36
 */
@Controller
@ResponseBody
@RequestMapping("/web/syllabus")
public class SyllabusController {

	@Autowired
	private SyllabusService syllabusService;

	/**
	 * 添加课表
	 * 
	 * @param syllabus
	 *            课表
	 */
	@RequestMapping("/insertSyllabus")
	public AjaxRes insertSyllabus(SlfSyllabus syllabus, AjaxRes ajaxRes) {
		try {
			this.syllabusService.insertSyllabus(syllabus);
			ajaxRes.setSucceedMsg(Const.SAVE_SUCCEED);
		} catch (Exception e) {
			ajaxRes.setFailMsg(e.getMessage());
		}
		return ajaxRes;
	}

	/**
	 * 批量删除课表
	 * 
	 * @param syllabusIds
	 *            课表ID集合
	 */
	@RequestMapping("/deleteSyllabuss")
	public AjaxRes deleteSyllabuss(@RequestParam("syllabusIds") List<Integer> syllabusIds, AjaxRes ajaxRes) {
		try {
			this.syllabusService.deleteSyllabuss(syllabusIds);
			ajaxRes.setSucceedMsg(Const.DEL_SUCCEED);
		} catch (Exception e) {
			ajaxRes.setFailMsg(e.getMessage());
		}
		return ajaxRes;
	}

	/**
	 * 修改课表
	 * 
	 * @param syllabus
	 *            课表
	 */
	@RequestMapping("/updateSyllabus")
	public AjaxRes updateSyllabus(SlfSyllabus syllabus, AjaxRes ajaxRes) {
		try {
			this.syllabusService.updateSyllabus(syllabus);
			ajaxRes.setSucceedMsg(Const.UPDATE_SUCCEED);
		} catch (Exception e) {
			ajaxRes.setFailMsg(e.getMessage());
		}
		return ajaxRes;
	}

	/**
	 * 查询课表
	 * 
	 * @param syllabusId
	 *            课表ID
	 */
	@RequestMapping("/getSyllabus")
	public AjaxRes getSyllabus(@RequestParam("syllabusId") Integer syllabusId, AjaxRes ajaxRes) {
		try {
			SlfSyllabusDto slfSyllabus = this.syllabusService.getSyllabus(syllabusId);
			ajaxRes.setSucceed(slfSyllabus,Const.DATA_SUCCEED);
		} catch (Exception e) {
			ajaxRes.setFailMsg(e.getMessage());
		}
		return ajaxRes;
	}

	/**
	 * 查询课表
	 * 
	 * @param syllabusId
	 *            课表ID
	 */
	@RequestMapping("/getSyllabusList")
	public AjaxRes getSyllabusList(@RequestParam Map<String, Object> map, AjaxRes ajaxRes) {
		try {
			List<SlfSyllabus> slfSyllabus = this.syllabusService.getSyllabusList(map);
			ajaxRes.setSucceed(slfSyllabus, Const.DATA_SUCCEED);
		} catch (Exception e) {
			ajaxRes.setFailMsg(e.getMessage());
		}
		return ajaxRes;
	}


	/**
	 * 查询周数
	 * 
	 */
	@RequestMapping("/getSelectWeek")
	public AjaxRes getSelectWeek(AjaxRes ajaxRes) {
		try {
			List<SelectDto> weeks = this.syllabusService.getSelectWeek();
			ajaxRes.setSucceed(weeks, Const.DATA_SUCCEED);
		} catch (Exception e) {
			ajaxRes.setFailMsg(e.getMessage());
		}
		return ajaxRes;
	}

}
